package com.task.manage.system.service.impl;

import java.util.List;

import com.task.manage.common.utils.DateUtils;
import com.task.manage.system.domain.MerchantInfo;
import com.task.manage.system.domain.TaskReveiveRecord;
import com.task.manage.system.mapper.MerchantTaskPriorityMapper;
import com.task.manage.system.mapper.TaskReveiveRecordMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.task.manage.system.mapper.MerchantTaskMapper;
import com.task.manage.system.domain.MerchantTask;
import com.task.manage.system.service.IMerchantTaskService;
import com.task.manage.common.core.text.Convert;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * 商家任务Service业务层处理
 *
 * @author ruoyi
 * @date 2024-05-09
 */
@Service
public class MerchantTaskServiceImpl implements IMerchantTaskService {
    @Resource
    private MerchantTaskMapper merchantTaskMapper;

    @Resource
    private TaskReveiveRecordMapper taskReveiveRecordMapper;

    @Resource
    private MerchantTaskPriorityMapper merchantTaskPriorityMapper;

    /**
     * 查询商家任务
     *
     * @param id 商家任务主键
     * @return 商家任务
     */
    @Override
    public MerchantTask selectMerchantTaskById(Long id) {
        return merchantTaskMapper.selectMerchantTaskById(id);
    }

    /**
     * 查询商家任务列表
     *
     * @param merchantTask 商家任务
     * @return 商家任务
     */
    @Override
    public List<MerchantTask> selectMerchantTaskList(MerchantTask merchantTask) {
        return merchantTaskMapper.selectMerchantTaskList(merchantTask);
    }

    /**
     * 新增商家任务
     *
     * @param merchantTask 商家任务
     * @return 结果
     */
    @Override
    public int insertMerchantTask(MerchantTask merchantTask) {
        merchantTask.setCreateTime(DateUtils.getNowDate());
        return merchantTaskMapper.insertMerchantTask(merchantTask);
    }

    /**
     * 修改商家任务
     *
     * @param merchantTask 商家任务
     * @return 结果
     */
    @Override
    public int updateMerchantTask(MerchantTask merchantTask) {
        merchantTask.setUpdateTime(DateUtils.getNowDate());
        return merchantTaskMapper.updateMerchantTask(merchantTask);
    }

    /**
     * 批量删除商家任务
     *
     * @param ids 需要删除的商家任务主键
     * @return 结果
     */
    @Override
    public int deleteMerchantTaskByIds(String ids) {
        return merchantTaskMapper.deleteMerchantTaskByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除商家任务信息
     *
     * @param id 商家任务主键
     * @return 结果
     */
    @Override
    public int deleteMerchantTaskById(Long id) {
        return merchantTaskMapper.deleteMerchantTaskById(id);
    }

    @Override
    public List<TaskReveiveRecord> selectaskRecordList(Long id) {
        return merchantTaskMapper.selectaskRecordList(id);
    }

    @Override
    public List<MerchantTask> selectTaskList() {
        return merchantTaskMapper.selectTaskList();
    }

    @Override
    @Transactional
    public void deleteTaskInfo(String ids) {
        //删除商家任务
        merchantTaskMapper.deleteMerchantTaskByIds(Convert.toStrArray(ids));
        //删除task_redord
        taskReveiveRecordMapper.deleteTaskReveiveRecordByTaskIds(Convert.toStrArray(ids));
        //删除商家任务优先级表
        merchantTaskPriorityMapper.deleteMerchantTaskPriorityByTaskIds(Convert.toStrArray(ids));
    }

    @Override
    public List<MerchantTask>  selectByProduct(String productLink) {
        return merchantTaskMapper.selectByProduct(productLink);
    }
}
